<template>
  <view>
    <!-- 分类开始 -->
    <view class="home_category">
      <navigator
        class="category_item"
        v-for="item in category"
        :key="item.id"
        :url="`/pages/imageCategory/index?id=${item.id}`"
      >
        <image :src="item.cover" mode="aspectFill" />
        <view class="category_name" v-text="item.name"></view>
      </navigator>
    </view>
    <!-- 分类结束 -->
  </view>
</template>

<script>
export default {
  data() {
    return {
      category: [],
    };
  },
  methods: {
    /* 获取接口数据 */
    getList() {
      this.request({
        url: "http://157.122.54.189:9088/image/v1/vertical/category",
      }).then((result) => {
        console.log(result);
        this.category = result.res.category;
      });
    },
  },
  /* 组件的生命周期函数，监听组件的挂载(挂载到Vue)，并不能监听子组件的完全挂载 */
  mounted() {
    // 修改页面的标题(navigationBarTitleText)
    uni.setNavigationBarTitle({
      title: "分类",
    });
    this.getList();
  },
};
</script>

<style lang="scss">
.home_category {
  display: flex;
  flex-wrap: wrap; // 换行
  .category_item {
    width: 33.3%;
    position: relative;
    border: 3rpx solid #fff;
    image {
      height: 240rpx;
    }

    .category_name {
      position: absolute;
      width: 100%;
      height: 50rpx;
      left: 0;
      bottom: 0;
      color: #fff;
      // css3 渐变样式的实现
      background-image: linear-gradient(
        to right top,
        rgba(0, 0, 0, 0.2),
        rgba(0, 0, 0, 0)
      );
      font-size: 40rpx;
      display: flex;
      align-items: center;
      padding-left: 20rpx;
    }
  }
}
</style>